package com.xinqi.modules.chat.chat.chat.controller.web;

import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.chat.chat.chat.service.ChatTranRecordService;
import com.xinqi.modules.chat.chat.group.dto.req.ChatTranRecordAddDTO;
import com.xinqi.modules.chat.chat.group.dto.rsp.ChatTranRecordResultDTO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * WEB -- 转发记录
 *
 * @version V1.0
 * @Title:
 * @ClassName: com.xinqi.modules.chat.chat.chat.controller.web.ChatTranRecordWebController.java
 * @Description:
 * @Copyright 星齐科技（云南）有限公司 - Powered By 技术部
 * @author: yyzhen
 * @date: 2023/5/19 9:08
 */
@Validated
@RestController
@RequestMapping("/web/chat-tran-record")
@RequiredArgsConstructor
public class ChatTranRecordWebController {
    private final ChatTranRecordService chatTranRecordService;

    /**
     * 添加转发记录
     *
     * @param dto
     * @return
     */
    @Operation(summary = "添加转发记录")
    @PostMapping("create")
    public R createTranRecord(@Validated @RequestBody ChatTranRecordAddDTO dto) {
        dto.setOperationUserId(LoginHelper.getUserId());
        if (chatTranRecordService.replaceChatTranRecord(dto)) {
            return R.ok(MessageUtils.message("chat.chat.tran.record.success"));
        } else {
            return R.error(MessageUtils.message("chat.chat.tran.record.fail"));
        }
    }

    /**
     * 查询最近转发（会话单一，查询最多六条）
     *
     * @return
     */
    @Operation(summary = "查询最近转发")
    @PostMapping("find")
    public R<List<ChatTranRecordResultDTO>> findTranRecord() {
        return R.data(chatTranRecordService.recentChatTranRecordList(LoginHelper.getUserId()));
    }

}
